package systema;

import framework.Converter;
import framework.Dropper;
import framework.FileDataSource;
import framework.IConvertFunction;
import framework.converters.ConvertFtMt;
import framework.converters.ConvertTempFC;
import framework.sinkers.FileSink;
import framework.sinkers.SystemsABCFormatter;
import framework.Constants;

import java.io.FileNotFoundException;
import java.util.Hashtable;

/**
 */
public class SystemAPlumber {

    public static void main(String [] args) throws FileNotFoundException, InterruptedException {
    	
    	// verify if there are sufficient arguments to start the program
    	if(args.length != 2){
    		System.out.println("Wrong usage of program arguments!");
    		System.out.println("Systems usage: <Source filename> <Sink filename> \n \t ");
    		System.exit(0);
    	}
    	
    	String argSource = args[0];
        String argSink = args[1];
        
    	FileDataSource src = new FileDataSource(argSource);

        int [] printOrder = {Constants.TIME_ID,Constants.TEMPERATURE_ID,Constants.ALTITUDE_ID};
        FileSink sink = new FileSink(argSink, printOrder, new SystemsABCFormatter());

        Hashtable<Integer, IConvertFunction> mappings = new Hashtable<Integer, IConvertFunction>();
        mappings.put(Constants.TEMPERATURE_ID, new ConvertTempFC());
        mappings.put(Constants.ALTITUDE_ID, new ConvertFtMt());
        Converter conv = new Converter(mappings);

        int [] toDrop = {Constants.VELOCITY_ID,Constants.PRESSURE_ID,Constants.ATTITUDE_ID};
        Dropper drop = new Dropper(toDrop);

        sink.Connect(conv,0);
        conv.Connect(drop,0);
        drop.Connect(src,0);


        src.start();
        drop.start();
        conv.start();
        sink.start();
    }

}
